# Maintainer: Ricky Wu <rickleaf.wu@gmail.com>

_realname=luarocks
pkgbase=mingw-w64-lua-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-lua51-${_realname}")
pkgver=2.4.4
pkgrel=2
pkgdesc="the package manager for Lua modules (mingw-w64)"
arch=('any')
url="https://luarocks.org"
license=("MIT")
install=luarocks-${CARCH}.install
depends=("${MINGW_PACKAGE_PREFIX}-lua51")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "unzip")
options=('staticlibs' 'strip')
source=("https://luarocks.org/releases/${_realname}-${pkgver}.tar.gz"
        "mingw32-msys2.patch")
sha256sums=('3938df33de33752ff2c526e604410af3dceb4b7ff06a770bc4a240de80a1f934'
            '620d094f4f2fcf72a6c09699d84baa3f9a1a745f1cdf14e89d93375f5ad0998c')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/mingw32-msys2.patch
}

build() {
  #mkdir -p "build-${MINGW_CHOST}"
  cd "${srcdir}/${_realname}-${pkgver}"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --with-lua-include=${MINGW_PREFIX}/include/lua5.1 \
    --lua-version=5.1 \
    --lua-suffix=5.1.exe

  make build
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}"
  make DESTDIR="${pkgdir}" install
}
